package com.college.controller.products;

import com.college.common.constant.ErrorMsg;
import com.college.common.pojo.ao.OrderAddress;
import com.college.common.pojo.vo.ResultVo;
import com.college.products.service.OrderAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/order-address")
@Api(tags = "订单地址")
@Slf4j
public class OrderAddressController {

    @Autowired
    private OrderAddressService orderAddressService;

    @ApiOperation(value = "新增订单地址")
    @PostMapping("/add")
    public ResultVo addOrderAddress(@RequestBody OrderAddress orderAddress){
        return ResultVo.success(orderAddressService.addOrderAddress(orderAddress));
    }

    @ApiOperation(value = "修改订单地址")
    @PostMapping("/update")
    public ResultVo updateOrderAddress(@RequestBody OrderAddress orderAddress){
        if(orderAddressService.updateOrderAddress(orderAddress)){
            return ResultVo.success(orderAddress);
        }
        return ResultVo.fail(ErrorMsg.SYSTEM_ERROR);
    }

    @ApiOperation(value = "获取订单地址信息")
    @GetMapping("/info")
    public ResultVo getOrderAddress(@RequestParam Long orderId){
        return ResultVo.success(orderAddressService.getOrderAddress(orderId));
    }
}
